package ro.flashbite.game_engine.view
{
	import flash.display.Sprite;
	
	import ro.flashbite.errors.OverrideError;
	import ro.flashbite.game_engine.interfaces.ILevelToEngine;
	import ro.flashbite.helpers.MovieClipHelpers;
	import ro.flashbite.interfaces.ISleepWakeupDestroy;
	import ro.flashbite.loggers.ILogger;
	import ro.flashbite.loggers.LoggerFactory;
	
	/**
	 * Base implementation of a simple level
	 * 
	 * v 1.0
	 * 
	 * @author Adrian Barbu
	 */	
	public class BaseLevel extends Sprite implements ISleepWakeupDestroy
	{
		/**
		 * used for callbacks 
		 */		
		protected var _gameEngine	:	ILevelToEngine;
		/**
		 * used to know the id from assetManager loaded module of the game 
		 */
		protected var _ID			:	String;
		/**
		 * logger for debugging 
		 */		
		protected var _logger		:	ILogger;
		
		// ================================================================================================================================
		// CONSTRUCTOR
		// ================================================================================================================================
		
		public function BaseLevel(ID:String, gameEngine:ILevelToEngine)
		{
			_constructor(ID, gameEngine);
		}
		private function _constructor(ID:String, gameEngine:ILevelToEngine):void
		{
			_ID = ID;
			_gameEngine = gameEngine;
			_logger = LoggerFactory.getLogger(_ID);
		}
		
		// ================================================================================================================================
		// PUBLIC
		// ================================================================================================================================
		
		public function initialize():void
		{
			throw new OverrideError();
			
			levelInitialized();
		}
		
		//start interaction
		public function start():void
		{
			throw new OverrideError();
		}
		
		//reset game
		public function reset():void
		{
			throw new OverrideError();
		}
		
		// ================================================================================================================================
		// ISleepWakeupDestroy
		// ================================================================================================================================
		
		public function sleep():void
		{
			throw new OverrideError();
		}
		
		public function wakeup():void
		{
			throw new OverrideError();
		}
		
		public function destroy():void
		{
			_ID = null;
			_gameEngine = null;
			if (_logger) {
				LoggerFactory.clearLogger(_logger.name);
				_logger = null;
			}
			
			MovieClipHelpers.removeAllChildren(this);
		}
		
		// ================================================================================================================================
		// PROTECTED to be used by children
		// ================================================================================================================================
		
		protected final function levelInitialized():void { _gameEngine.setLevelInitComplete(_ID); }
		
		// ================================================================================================================================
		// GETTERS, SETTERS
		// ================================================================================================================================
		
		public function get ID():String { return _ID; }
	}
}